import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [

  {
    path: '/',
    name: 'login',
    component: () => import(/* webpackChunkName: "about" */ '../views/login.vue')
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('../views/home.vue'),
    children:[
      {
        path: '/home/registration/onsite',
        name: 'onsite',
        component: () => import('../components/register/register.vue')
      },
      {
        path: '/home/registration/retreat',
        name: 'retreat',
        component: () => import('../components/register/retreat.vue')
      },
      {
        path: '/home/outpatient/call',
        name: 'call',
        component: () => import('../components/outpatient/call.vue')
      },
      {
        path: '/home/outpatient/homepage',
        name: 'homepage',
        component: () => import('../components/outpatient/homepage.vue')
      },
      {
        path: '/home/outpatient/test',
        name: 'test',
        component: () => import('../components/outpatient/test.vue')
      },
      {
        path: '/home/SelfInfo',
        name: 'SelfInfo',
        component: () => import('../components/register/SelfInfo.vue')
      }

    ]
 }

]

const router = createRouter({
  history: createWebHashHistory(),  routes
})
import store from "@/store"
router.beforeEach(function (to,from,next){
  let arr=['/home','/home/registration/onsite','/home/registration/retreat','/home/outpatient/call','/home/outpatient/homepage']
  for (let u in arr) {
    console.log(arr[u])

    console.log(to.path)
    console.log(arr)
    if (arr[u]==to.path){
      let isLogin=store.state.emp.id
      console.log(arr[u])
      console.log(isLogin)
      if (isLogin==null){
        router.push("/")
      }
    }
  }
  next()
})
export default router
